# coding:utf-8


from com.power.auto.test.config.EnvManager import *


class HessianInvoker(object):

    def __init__(self):
        if isJVMStarted():
            jd_class = JClass("power.hessian.client.HessianClient")
            self.jd_class_instance = jd_class()
        else:
            print('EnvManager.get_lib_path()=%s' % EnvManager.get_lib_path())
            startJVM(getDefaultJVMPath(), '-ea', '-Djava.ext.dirs=%s' % EnvManager.get_lib_path())
            jd_class = JClass("power.hessian.client.HessianClient")
            self.jd_class_instance = jd_class()

    def invoke_hessian(self, url, class_name, invoke_methond, param_class, param_json):
        result = ''
        # try:
        result = self.jd_class_instance.invokeHessian(url, class_name, invoke_methond, param_class, param_json)
        print('调用hessian返回结果' + result)
        return result


if __name__ == '__main__':
    result = HessianInvoker().invoke_hessian('http://127.0.0.1:8080/power-hessian/hessian/PayFacade',
                                             'com.yeepay.power.facade.order.PayFacade',
                                             'createOrderToken',
                                             'com.yeepay.power.dto.order.CreateOrderTokenRequestDTO',
                                             '{\"orderSourceTypeEnums\":\"PC\"}')
    print(result)

instance = HessianInvoker()
